#ifndef CACHE_H
#define CACHE_H

//-----------------------------------------------------------------------------
//
// cache.h
//
// Group:
//    Doug Kline,          dakline@ncsu.edu
//    Mauricio Del Carpio, mgdelcar@ncsu.edu
//    Josh Jodrey,         jdjodrey@ncsu.edu
//
//
// This class handles cacheing web pages.
//
//-----------------------------------------------------------------------------

#include <linux/in.h>
#include <linux/time.h>
#include "config.h"
#include "cache.h"


#define COMMAND_BUFSIZE  4096
#define HOSTNAME_BUFSIZE 1024
#define PATH_BUFSIZE     2048
#define LASTMOD_BUFSIZE    64
#define FILENAME_BUFSIZE   64
#define RESPONSE_BUFSIZE 1024

struct cacheItem
{
   struct semaphore itemLock;
   int             valid;                      // Is this item valid?
   char            hostname[HOSTNAME_BUFSIZE]; // Stores the destination
   char            path[PATH_BUFSIZE];         // Stores the requested resource
   struct sockaddr_in  clientAddr;             // Stores the requesting host address
   int             server_port;                // The port number (specifed or 80)
   char            lastMod[LASTMOD_BUFSIZE];   // Last-Modified from the response

   void           *buf_p;                      // Where the response is stored
   int             size;                       // Size of the buffer.
   struct timeval  timestamp;                  // This item's creation time
    
   struct cacheItem *prev_p;                   // Linked list
   struct cacheItem *next_p;                   // Linked list   
};

struct cacheItem *cacheGet(char *command, char *host, char *path,
                           struct sockaddr_in clientAddr);

struct cacheItem *newCacheItem(void);
void deleteCacheItem(struct cacheItem *item_p);

void insertItem(struct cacheItem *item_p);

void unlock(struct cacheItem *item_p);

void appendBuf(struct cacheItem *item_p, void *buf_p, int size);


#endif // CACHE_H
